Passed
Pull Request — master (#213)
by
unknown
01:40
created

LeaveRequest   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 123
dl 0
loc 142
rs 10
c 0
b 0
f 0
wmc 15

15 Functions

Rating   Name   Duplication   Size   Complexity  
A getComment 0 3 1
A accept 0 10 1
A getEndDate 0 3 1
A isStartsAllDay 0 3 1
A getModerateAt 0 3 1
A refuse 0 10 1
A getModerationComment 0 3 1
A getModerator 0 3 1
A isEndsAllDay 0 3 1
A getUser 0 3 1
A getStatus 0 3 1
A getId 0 3 1
A getStartDate 0 3 1
A getType 0 3 1
A update 0 15 1
1
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
2
import { User } from '../User/User.entity';
3
4
export enum Status {
5
  PENDING = 'pending',
6
  ACCEPTED = 'accepted',
7
  REFUSED = 'refused'
8
}
9
10
export enum Type {
11
  PAID = 'paid',
12
  UNPAID = 'unpaid',
13
  SPECIAL = 'special',
14
  MEDICAL = 'medical'
15
}
16
17
@Entity()
18
export class LeaveRequest {
19
  @PrimaryGeneratedColumn('uuid')
20
  private id: string;
21
22
  @Column('enum', { enum: Status, nullable: false })
23
  private status: Status;
24
25
  @Column('enum', { enum: Type, nullable: false })
26
  private type: Type;
27
28
  @Column({ type: 'timestamp', nullable: false })
29
  private startDate: string;
30
31
  @Column({ type: 'boolean', nullable: false, default: true })
32
  private startsAllDay: boolean;
33
34
  @Column({ type: 'timestamp', nullable: false })
35
  private endDate: string;
36
37
  @Column({ type: 'boolean', nullable: false, default: true })
38
  private endsAllDay: boolean;
39
40
  @Column({ type: 'varchar', nullable: true })
41
  private comment: string;
42
43
  @Column({ type: 'varchar', nullable: true })
44
  private moderationComment: string;
45
46
  @Column({ type: 'timestamp', nullable: true })
47
  private moderateAt: string;
48
49
  @ManyToOne(type => User, { nullable: true, onDelete: 'SET NULL' })
50
  private moderator: User;
51
52
  @ManyToOne(type => User, { nullable: false, onDelete: 'CASCADE' })
53
  private user: User;
54
55
  constructor(
56
    user: User,
57
    type: Type,
58
    startDate: string,
59
    startsAllDay: boolean,
60
    endDate: string,
61
    endsAllDay: boolean,
62
    comment?: string
63
  ) {
64
    this.status = Status.PENDING;
65
    this.user = user;
66
    this.type = type;
67
    this.startDate = startDate;
68
    this.startsAllDay = startsAllDay;
69
    this.endDate = endDate;
70
    this.endsAllDay = endsAllDay;
71
    this.comment = comment;
72
  }
73
74
  public getId(): string {
75
    return this.id;
76
  }
77
78
  public getUser(): User {
79
    return this.user;
80
  }
81
82
  public getStatus(): Status {
83
    return this.status;
84
  }
85
86
  public getType(): Type {
87
    return this.type;
88
  }
89
90
  public getStartDate(): string {
91
    return this.startDate;
92
  }
93
94
  public isStartsAllDay(): boolean {
95
    return this.startsAllDay;
96
  }
97
98
  public getEndDate(): string {
99
    return this.endDate;
100
  }
101
102
  public isEndsAllDay(): boolean {
103
    return this.endsAllDay;
104
  }
105
106
  public getComment(): string {
107
    return this.comment;
108
  }
109
110
  public getModerator(): User {
111
    return this.moderator;
112
  }
113
114
  public getModerateAt(): string {
115
    return this.moderateAt;
116
  }
117
118
  public getModerationComment(): string {
119
    return this.moderationComment;
120
  }
121
122
  public refuse(
123
    moderator: User,
124
    date: string,
125
    moderationComment?: string
126
  ): void {
127
    this.status = Status.REFUSED;
128
    this.moderator = moderator;
129
    this.moderateAt = date;
130
    this.moderationComment = moderationComment;
131
  }
132
133
  public accept(
134
    moderator: User,
135
    date: string,
136
    moderationComment?: string
137
  ): void {
138
    this.status = Status.ACCEPTED;
139
    this.moderator = moderator;
140
    this.moderateAt = date;
141
    this.moderationComment = moderationComment;
142
  }
143
144
  public update(
145
    type: Type,
146
    startDate: string,
147
    startsAllDay: boolean,
148
    endDate: string,
149
    endsAllDay: boolean,
150
    comment?: string
151
  ): void {
152
    this.type = type;
153
    this.startDate = startDate;
154
    this.startsAllDay = startsAllDay;
155
    this.endDate = endDate;
156
    this.endsAllDay = endsAllDay;
157
    this.comment = comment;
158
  }
159
}
160